using Microsoft.Extensions.DependencyInjection;
using Microsoft.Maui;
using Microsoft.Maui.Controls.Hosting;
using Microsoft.Maui.Hosting;
using Microsoft.Extensions.Logging;
using MauiApp.Views.Controls;
using MauiApp.Services;
using MauiApp.ViewModels;

#if ANDROID
using MauiApp.Handlers;
#endif

namespace MauiApp
{
    public static class MauiProgram
    {
        public static Microsoft.Maui.Hosting.MauiApp CreateMauiApp()
        {
            var builder = Microsoft.Maui.Hosting.MauiApp.CreateBuilder();
            builder
                .UseMauiApp<App>()
                .ConfigureFonts(fonts =>
                {
                    fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
                    fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
                });

#if DEBUG
            builder.Logging.AddDebug();
#endif

            // 注册服务
            builder.Services.AddSingleton<IApiService, ApiService>();

            // 注册ViewModels
            builder.Services.AddTransient<MainViewModel>();
            builder.Services.AddTransient<StudyStatsViewModel>();
            builder.Services.AddTransient<TypeManageViewModel>();
            builder.Services.AddTransient<LoginViewModel>();

#if ANDROID
            builder.ConfigureMauiHandlers(handlers =>
            {
                handlers.AddHandler(typeof(ZoomableImage), typeof(ZoomableImageHandler));
            });
#endif

            return builder.Build();
        }
    }
}
